package com.pearl.web.demo.servlet;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author TangDan
 * @version 1.0
 * @since 2023/3/20
 */
// 拦截器的排序，数字越小，越先执行
@Order(1)
// filterName: 过滤器名称
// urlPatterns: 拦截的URL
@Component
@WebFilter(filterName = "myFilter", urlPatterns = {"/*"})
public class MyFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("---------进入MyFilter前置------------");
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("------------进入MyFilter后置--------");
    }
}
